from os import name
from loguru import logger 


class Log:
    log=None
    errLog=None
    sysLog=None
    traceLog=None

    def __init__(self):
        # 日志输出规范
        logger_format = "{time:YYYY-MM-DD HH:mm:ss,SSS} [{thread}] - {message}"
        # 日志分割时间
        rotation = "00:00"
        # 日志保留时间， 空格一定要有
        retention="7 days" 

        # filter = lambda record: record
        logger.add('logs/{time:YYYY-MM-DD}/err_{time:YYYY-MM-DD}.log', rotation=rotation, retention=retention, format=logger_format, filter=lambda record: record["extra"].get("name") == "err")
        logger.add('logs/{time:YYYY-MM-DD}/sys_{time:YYYY-MM-DD}.log', rotation=rotation, retention=retention, format=logger_format, filter=lambda record: record["extra"].get("name") == "sys")
        logger.add('logs/{time:YYYY-MM-DD}/trace_{time:YYYY-MM-DD}.log', rotation=rotation, retention=retention, format=logger_format,filter=lambda record: record["extra"].get("name") == "trace")

        self.errLog = logger.bind(name="err")
        self.sysLog = logger.bind(name="sys")
        self.traceLog = logger.bind(name="trace")

    def err(self, msg):
        self.errLog.error(msg)

    def sys(self, msg):
        self.sysLog.info(msg)
    
    def trace(self, msg):
        self.traceLog.info(msg)


log = Log()